//
//  BusinessActInfo.m
//  HappyStore
//
//  Created by 李小辉 on 16/6/13.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "BusinessActInfo.h"
#import "BusinessActivityView.h"
#import "HeadPageView.h"
#import "UsedTool.h"
#import "PinLunCell.h"
#import "PinLunVC.h"
#import "SingupBaoMingPepole.h"
@interface BusinessActInfo ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIButton *btnBaoMing;//报名按钮
@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSDictionary *dicData;//数据源
@property (strong, nonatomic) HeadPageView *topView;//顶部视图
@property (strong, nonatomic) BusinessActivityView *midouView;//上面的视图
@property (strong, nonatomic) NSMutableArray *commentsList;//评论
@property (strong, nonatomic) NSMutableArray *activitySignPeople;//已报名的人
@property (strong, nonatomic) NSMutableArray *TopPhotos;//顶部图片
@property (assign, nonatomic) NSInteger count;//记录点击（展开/收起）的次数
@property (assign, nonatomic) NSInteger page;
@property (strong, nonatomic) NSString *isFocus;//判断收藏
@property (strong, nonatomic) NSString *isZan; //判断赞
@property (strong, nonatomic) UIButton *rightBtn;//收藏按钮
@property (nonatomic) CGSize size;//记录上一标签的大小
@end

@implementation BusinessActInfo

//初始化

- (NSMutableArray *)TopPhotos{
    if (!_TopPhotos) {
        _TopPhotos = [NSMutableArray array];
    }
    return _TopPhotos;
}
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];
    }
    return _tableView;
}
- (NSDictionary *)dicData{
    if (!_dicData) {
        _dicData = [NSDictionary dictionary];
    }
    return _dicData;
}
- (NSMutableArray *)activitySignPeople{
    if (!_activitySignPeople) {
        _activitySignPeople = [NSMutableArray array];
    }
    return _activitySignPeople;
}
- (NSMutableArray *)commentsList{
    if (!_commentsList) {
        _commentsList = [NSMutableArray array];
    }
    return _commentsList;
}
- (BusinessActivityView *)midouView{
    if (!_midouView) {
        _midouView = [[[NSBundle mainBundle] loadNibNamed:@"BusinessActivityView" owner:self options:nil] lastObject];
    }
    return _midouView;
}
-(HeadPageView *)topView{
    if (!_topView) {
        _topView = [[[NSBundle mainBundle] loadNibNamed:@"HeadPageView" owner:self options:nil] lastObject];
    }
    return _topView;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"白色背景"] forBarMetrics:UIBarMetricsDefault];
    [self startNetWork];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"活动详情";
    titleLabel.textColor = RGB(45, 45, 45);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    
    //收藏
    self.rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [self.rightBtn addTarget:self action:@selector(clickRightBarEvent) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    //取消返回的文字
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
    //设置返回箭头
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"返回" highImage:@"返回"];
    self.navigationItem.leftBarButtonItem = leftItem;
    //展开按钮
    [self.midouView.clickButton addTarget:self action:@selector(clickButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    //查看更多报名按钮
    [self.midouView.singUpButton addTarget:self action:@selector(clickSingupButton) forControlEvents:UIControlEventTouchUpInside];
    //点赞
    [self.midouView.zanButton addTarget:self action:@selector(isZanEvent:) forControlEvents:UIControlEventTouchUpInside];
    //分享
    [self.midouView.shareButton addTarget:self action:@selector(shareEvent) forControlEvents:UIControlEventTouchUpInside];
    //评论
    [self.midouView.pinglunButton addTarget:self action:@selector(pinglunEvent:) forControlEvents:UIControlEventTouchUpInside];
    

    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.page = 1;
    self.count = 1;
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}
- (void)leftBarButtonItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 布局视图
- (void)setupTopView{
    
    [self.topView initPageViewWithViewController:self imagePaths:self.TopPhotos];
    self.topView.frame = CGRectMake(0, 0, screenW, 133);
    [self.scrollView addSubview:self.topView];
    [self setupMidouView];
}

- (void)setupMidouView{
    self.midouView.titleLabel.text = self.dicData[@"title"];
    CGSize titleSize = [self.midouView.titleLabel sizeThatFits:CGSizeMake(screenW-16, MAXFLOAT)];
    
    //时间
    NSString *timeStr = self.dicData[@"starttime"];
    //年月日
    NSString *yearStr = [timeStr substringToIndex:10];
    //几点
    NSString *timeString = [timeStr substringWithRange:NSMakeRange(10,6)];
    //周几
    NSString *weekStr = [UsedTool getWeekDayForstring:timeStr];
    
    self.midouView.timeLabel.text = [NSString stringWithFormat:@"%@ %@ %@",yearStr,weekStr,timeString];
    self.midouView.addressLabel.text = self.dicData[@"address"];
    self.midouView.organizerLabel.text = self.dicData[@"sponsor"];
    
    //显示金额、标签
    CGRect frameAdr = self.midouView.labelImage.frame;
    if (self.count==1 && titleSize.height>21) {
        frameAdr.origin.y += 20;
        if (self.count==1 && titleSize.height>42) {
            frameAdr.origin.y += 20;
        }
    }
    
    NSArray *arrayLabel = [self.dicData[@"lable"] componentsSeparatedByString:@","];
    for (int i = 0; i<arrayLabel.count; i++) {
        UILabel *labelLabel = [[UILabel alloc] init];
        labelLabel.text = arrayLabel[i];
        
        //文字居中
        labelLabel.textAlignment = NSTextAlignmentCenter;
        labelLabel.font = [UIFont systemFontOfSize:12];
        labelLabel.textColor = RGB(23, 176, 216);
        labelLabel.backgroundColor = RGB(217, 242, 255);
        //设置边框
        labelLabel.layer.borderWidth = 0.5f;
        labelLabel.layer.borderColor = RGB(23, 176, 216).CGColor;
        //自定义宽度
        labelLabel.numberOfLines = 1;
        labelLabel.lineBreakMode = NSLineBreakByCharWrapping;
        CGSize maxSize = CGSizeMake(MAXFLOAT, 20);
        
        CGSize size = [labelLabel sizeThatFits:maxSize];
        
        labelLabel.frame = CGRectMake(i%3*(self.size.width + 20) + frameAdr.origin.x + 19 + 11, i/3 * 21 + frameAdr.origin.y, size.width + 10,size.height + 3);
        
        if (labelLabel.text.length!=0) {
            [self.midouView addSubview:labelLabel];
            self.size = size;
            
        }

    }
    

    
//活动介绍
    self.midouView.descriptionLabel.text = self.dicData[@"description"];
    
    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:self.midouView.descriptionLabel.text];
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:8];
    [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [self.midouView.descriptionLabel.text length])];
    [self.midouView.descriptionLabel setAttributedText:attributedString1];
    [self.midouView.descriptionLabel sizeToFit];
    self.midouView.descriptionLabel.textAlignment = NSTextAlignmentLeft;
    CGSize desSize = [self.midouView.descriptionLabel sizeThatFits:CGSizeMake(screenW-40, MAXFLOAT)];
    
    
    //报名人数
    self.midouView.activitySingupNumber.text = [NSString stringWithFormat:@"%@",self.dicData[@"activitySignupNumber"]] ;
 
    
    //点赞人数、评论人数
    self.midouView.zanNumber.text = self.dicData[@"zanCount"];
    self.midouView.pinglunNumber.text = self.dicData[@"commentCount"];
    //报名人头像
    if (self.activitySignPeople.count != 0) {
        self.midouView.singupHeadPhoto.layer.cornerRadius = self.midouView.singupHeadPhoto.frame.size.height/2;
        self.midouView.singupHeadPhoto.layer.masksToBounds = YES;
        //认证
        self.midouView.isAuthState.hidden = [UsedTool authStateImageViewHidden:self.activitySignPeople[0][@"authState"]];
        [self.midouView.singupHeadPhoto sd_setImageWithURL:[NSURL URLWithString:self.activitySignPeople[0][@"headPhoto"]]];
        if (self.activitySignPeople.count>=2) {
            self.midouView.singupHeadPhoto1.layer.cornerRadius = 20;
            self.midouView.singupHeadPhoto1.layer.masksToBounds = YES;
            self.midouView.isAuthState1.hidden = [UsedTool authStateImageViewHidden:self.activitySignPeople[1][@"authState"]];
            [self.midouView.singupHeadPhoto1 sd_setImageWithURL:[NSURL URLWithString:self.activitySignPeople[1][@"headPhoto"]]];
        }
        if (self.activitySignPeople.count>=3) {
            self.midouView.singupHeadPhoto2.layer.cornerRadius = 20;
            self.midouView.singupHeadPhoto2.layer.masksToBounds = YES;
            self.midouView.isAuthState2.hidden = [UsedTool authStateImageViewHidden:self.activitySignPeople[2][@"authState"]];
            [self.midouView.singupHeadPhoto2 sd_setImageWithURL:[NSURL URLWithString:self.activitySignPeople[2][@"headPhoto"]]];
        }
        if (self.activitySignPeople.count>=4) {
            self.midouView.singupHeadPhoto3.layer.cornerRadius = 20;
            self.midouView.singupHeadPhoto3.layer.masksToBounds = YES;
            self.midouView.isAuthState3.hidden = [UsedTool authStateImageViewHidden:self.activitySignPeople[3][@"authState"]];
            [self.midouView.singupHeadPhoto3 sd_setImageWithURL:[NSURL URLWithString:self.activitySignPeople[3][@"headPhoto"]]];
        }
        if (self.activitySignPeople.count>=5) {
            self.midouView.singupHeadPhoto4.layer.cornerRadius = 20;
            self.midouView.singupHeadPhoto4.layer.masksToBounds = YES;
            self.midouView.isAuthState4.hidden = [UsedTool authStateImageViewHidden:self.activitySignPeople[4][@"authState"]];
            [self.midouView.singupHeadPhoto4 sd_setImageWithURL:[NSURL URLWithString:self.activitySignPeople[4][@"headPhoto"]]];
        }
    }
    
    self.midouView.frame = CGRectMake(0, self.topView.height, screenW, self.midouView.descriptionLabel.y+self.midouView.descriptionLabel.height +247);
    
   
    
    [self.scrollView addSubview:self.midouView];
   [self setupTabelView];
    self.scrollView.contentSize = CGSizeMake(screenW,self.midouView.height +247);
    
}


- (void)setupTabelView{
    self.tableView.bounces = NO;
    
    self.tableView.x=0;
    self.tableView.y = self.midouView.height +150;
    self.tableView.width = screenW;
    //self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, self.tableView.height, 0);
    
    [self.scrollView addSubview:self.tableView];
    //集成下拉加载更多评论
    [self setupDownRefresh];
    [self.tableView reloadData];
}

-(void)setupDownRefresh{

    
    self.scrollView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        self.page++;
        [self getMorePingLun];
    }];
}


#pragma mark - tableView DataSource


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.commentsList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *strCell = @"commentCell";
    UINib *nib = [UINib nibWithNibName:@"PinLunCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:strCell];
    PinLunCell *cell = [self.tableView dequeueReusableCellWithIdentifier:strCell];
    
    if (!cell) {
        cell = [[PinLunCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCell];
    }
    NSDictionary *dic = self.commentsList[indexPath.row];
    
    cell.posiTion.text = dic[@"posiTion"];
    if (dic[@"posiTion"]==nil||[dic[@"posiTion"] isEqualToString:@"null"] ) {
        cell.posiTion.text = @"";
    }
    [cell.headPhotoImageView sd_setImageWithURL:dic[@"headPhoto"] placeholderImage:[UIImage imageNamed:@"20100403114758394_4147"]];
    cell.headPhotoImageView.layer.cornerRadius = 23.0f;
    cell.headPhotoImageView.layer.masksToBounds = YES;
    cell.userName.text = dic[@"commentUsername"];
    if (dic[@"commentUsername"]==nil||[dic[@"commentUsername"] isEqualToString:@""]||[dic[@"commentUsername"] isEqualToString:@"null"]) {
        cell.userName.text = dic[@"commentAccount"];
    }
    cell.timeLabel.text = [CustomExcetion prettyDateWithReference:[CustomExcetion dateFromString:dic[@"createTime"]]];
//    if ([dic[@"authState"] integerValue]==2) {
//        cell.authStateImageView.image = [UIImage imageNamed:@"yirenzheng"];
//    }else{
//        
//        cell.authStateImageView.image = [UIImage imageNamed:@"weirenzheng"];
//    }
    //认证
    cell.isAuthState.hidden = [UsedTool authStateImageViewHidden:dic[@"authState"]];
    //会员图标
    cell.authStateImageView.image = [UsedTool setVipimage:dic[@"vipLevel"]];
    cell.commentContent.text = dic[@"content"];
    //  //判断上级
    cell.companyUserName.text = [UsedTool userType:dic[@"userType"] companyName:dic[@"companyName"] userAddress:dic[@"userAddress"]];
    CGSize sizeUserName = [cell.userName sizeThatFits:CGSizeMake(MAXFLOAT, 21)];
    CGSize sizePosition = [cell.posiTion sizeThatFits:CGSizeMake(MAXFLOAT, 21)];
    //名字长度控制
    if (sizePosition.width == 0) {
        if (sizeUserName.width > 170.0f) {
            cell.userNameConstraint.constant = 170.0f;
        }else{
            cell.userNameConstraint.constant = sizeUserName.width;
        }
    }else{
        if ((sizeUserName.width + sizePosition.width) <= 170.0f) {
            cell.userNameConstraint.constant = sizeUserName.width;
            cell.posiTionConstraint.constant = sizePosition.width;
        }else{
            
            if (sizeUserName.width >110.0f) {
                cell.userNameConstraint.constant = 110.0f;
            }else{
                cell.userNameConstraint.constant = sizeUserName.width;
            }
            if (sizePosition.width > 60.0f) {
                cell.posiTionConstraint.constant = 60.0f;
            }else{
                cell.posiTionConstraint.constant = sizePosition.width;
            }
        }
    }
    

    
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    PinLunCell *cell = [self tableView:self.tableView cellForRowAtIndexPath:indexPath];
    
    
    UILabel *label = [[UILabel alloc] init];
    label.text = self.commentsList[indexPath.row][@"content"];
    label.numberOfLines = 0;
    label.font = [UIFont systemFontOfSize:14];
    CGSize constranit = CGSizeMake(screenW-16, 2000.0f);
    CGSize size = [label.text sizeWithFont:label.font constrainedToSize:constranit lineBreakMode:UILineBreakModeWordWrap];
    self.tableView.height = self.tableView.contentSize.height;
    //self.midouView.height
    self.scrollView.contentSize = CGSizeMake(screenW,  self.tableView.height + self.midouView.height + 150);
    
    return cell.frame.size.height + size.height-12;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - 获取更多评论
- (void)getMorePingLun
{
    [self showRoundProgressWithTitle:@"请稍后..."];
    
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    
    [muDicParameters setObject:self.activityId forKey:@"activityId"];
    [muDicParameters setObject:[NSString stringWithFormat:@"%ld",self.page] forKey:@"page"];
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"manyComentActivity_app_activity.im"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        //NSLog(@"%@",dicInfo);
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            
            NSArray *aryInff = [dicInfo objectForKey:@"data"][@"record"];
            
            for (int i = 0; i<aryInff.count; i++) {
                [self.commentsList addObject:aryInff[i]];
            }
            
            if (aryInff.count == 10) {
                self.scrollView.mj_footer.hidden = NO;
            }else {
                self.scrollView.mj_footer.hidden = YES;
            }
            
            
            
            
            [self.tableView reloadData];
            
            [self hideBubble];
        }else {

            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];

        }
        
        [self.scrollView.mj_footer endRefreshing];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self.scrollView.mj_footer endRefreshing];

        [self showSingleIconBubble:error.localizedDescription];

    }];
}

#pragma mark - 按钮事件
//已经报名事件按钮
- (void)clickSingupButton{
    SingupBaoMingPepole *sinVC = [[SingupBaoMingPepole alloc] init];
    sinVC.activityId = self.activityId;
    [self.navigationController pushViewController:sinVC animated:YES];
}
//展开收起事件
- (void)clickButtonEvent:(UIButton *)btn{
    
    btn.selected = !btn.selected;
    self.count += 1;
    
    [self.tableView removeFromSuperview];
    
    if (self.count%2==0) {
        
        self.midouView.descriptionLabel.numberOfLines = 0;
        
    }else{
        self.midouView.descriptionLabel.numberOfLines = 4;
        
    }
    
    [self setupMidouView];
}



#pragma mark - 收藏、点赞、评论、报名
//收藏
- (void)clickRightBarEvent{
    
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
        
        //NSLog(@"self.isFocus:%@",self.isFocus);
        NSMutableDictionary * dic = [NSMutableDictionary dictionary];
        dic[@"userId"] = [USER_DEFAULTS objectForKey:@"userid"];
        dic[@"token"] = [USER_DEFAULTS objectForKey:@"token"];
        dic[@"resId"] = self.activityId;
        dic[@"resType"] = @(2);
        NSString *strURL = @"";
        if ([self.isFocus isEqualToString:@"否"]) {
            strURL = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"focusResources_app_action.im.lensum"];
            
        }else{
            strURL = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"focusResourcesCancel_app_action.im.lensum"];
        }
        
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager POST:strURL parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
            if ([dicInfo[@"result"] integerValue] == 1) {
                if ([self.isFocus isEqualToString:@"否"]) {

                    [self.rightBtn setImage:[UIImage imageNamed:@"shouchanghuang"] forState:UIControlStateNormal];
                    
                    self.isFocus = @"是";
                }else{
                    [self.rightBtn setImage:[UIImage imageNamed:@"shouchang"] forState:UIControlStateNormal];
                    self.isFocus =@"否";
                }
                [self showRightWithTitle:dicInfo[@"msg"] autoCloseTime:2];
            }
            if ([dicInfo[@"result"] integerValue] == 2) {
                if ([self.isFocus isEqualToString:@"否"] ) {
                    self.isFocus =@"否";
                }else{
                    self.isFocus = @"是";
                }

                [self showRightWithTitle:dicInfo[@"msg"] autoCloseTime:2];
            }
            
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

            [self showSingleIconBubble:@"网络连接错误"];

        }];
        
        
        
    }else{
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
    }

  }
//点赞
- (void)isZanEvent:(UIButton *)sender{
    //8.活动点赞、取消http://localhost:8080/lensum/zanActivityNews_app_activity.im.lensum?token=XF2YkxodEFLmVot6svnA&userId=9&resId=1&type=1    1-点赞 2-取消
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
        [self showRoundProgressWithTitle:@"请稍后..."];
        NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
        [muDicParameters setObject:self.activityId forKey:@"resId"];//资源id
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
        
        NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"zanActivityNews_app_activity.im.lensum"];
        
        if ([self.isZan isEqualToString:@"否"]) {
            [muDicParameters setObject:@(1) forKey:@"type"];
        }else {
            [muDicParameters setObject:@(2) forKey:@"type"];
        }
        
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            

            
            NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
            
            if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                
                if ([self.isZan isEqualToString:@"否"]) {
                    [self.midouView.zanButton setImage:[UIImage imageNamed:@"dainzan"] forState:UIControlStateNormal] ;
                    self.isZan = @"是";
                    
                }else {
                    [self.midouView.zanButton setImage:[UIImage imageNamed:@"点赞-1"] forState:UIControlStateNormal];
                    self.isZan = @"否";
                    
                }

                [self showRightWithTitle:dicInfo[@"msg"] autoCloseTime:2];
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

           [self showSingleIconBubble:error.localizedDescription];

        }];
    }else {
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
    }
}
//分享
- (void)shareEvent{
    
    [ShareMsg shareMsgBOOLType:YES titleStr:nil contentStr:nil urlStr:nil imageAry:nil];
}
//评论
- (void)pinglunEvent:(UIButton *)sender{
    PinLunVC * pVC = [[PinLunVC alloc]init];
    
    pVC.resId = self.activityId;
    pVC.str = @"commentActivity_app_action.im.lensum";
    [self.navigationController pushViewController:pVC animated:YES];
}
//报名
- (IBAction)signUpButtonEvent:(id)sender {
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"报名" message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
        alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
        UITextField *tfphoto = [alert textFieldAtIndex:0];
        tfphoto.placeholder = @"请输入联系电话";
        tfphoto.keyboardType = UIKeyboardAppearanceDefault;
        
        UITextField *urlField = [alert textFieldAtIndex:1];
        urlField.placeholder = @"说点什么吧";
        urlField.secureTextEntry = NO;
        
        
        [alert showAlertWithCompletionHandler:^(NSInteger buttonIndex) {
            if(buttonIndex == 1){
                UITextField *tfPhone=[alert textFieldAtIndex:0];
                UITextField *tfContent = [alert textFieldAtIndex:1];
                if (tfPhone.text.length > 0) {
                    [self showRoundProgressWithTitle:@"请稍后..."];
                    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
                    [muDicParameters setObject:self.activityId forKey:@"activityId"];//资源id
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                    [muDicParameters setObject:tfPhone.text forKey:@"phone"];
                    [muDicParameters setObject:tfContent.text forKey:@"content"];
                    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"signUpActivity_app_activity.im.lensum"];
                    
                    
                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
                        
                    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                        
                        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                        //NSLog(@"%@",dicInfo);
                        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                            [self.btnBaoMing setTitle:@"已报名" forState:UIControlStateNormal];
                            self.btnBaoMing.userInteractionEnabled = NO;

                            [self showRightWithTitle:@"报名成功,请按时参加!" autoCloseTime:2];
                        }else {
                            self.btnBaoMing.userInteractionEnabled = YES;

                            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                        }
                        
                    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                        [self showSingleIconBubble:error.localizedDescription];

                    }];
                }
            }
        }];
        
        
    }else {
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
    }
}



#pragma mark -请求任务
- (void)startNetWork
{
    [self showRoundProgressWithTitle:@"请稍后..."];
    
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    //    userId=当前登录用户id&projectId=项目id
    
    [muDicParameters setObject:self.activityId forKey:@"activityId"];
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
    }
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"activityDetail_app_activity.im"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        //NSLog(@"%@",dicInfo);
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            
            self.dicData = [dicInfo objectForKey:@"data"];
            //判断收藏
            self.isFocus = self.dicData[@"isfocus"];
            if ([self.isFocus isEqualToString:@"是"]) {
                [self.rightBtn setImage:[UIImage imageNamed:@"shouchanghuang"] forState:UIControlStateNormal];
            }else{
                [self.rightBtn setImage:[UIImage imageNamed:@"shouchang"] forState:UIControlStateNormal];
            }
            //判断点赞
            self.isZan = self.dicData[@"isZan"];
            if ([self.isZan isEqualToString:@"是"]) {
                [self.midouView.zanButton setImage:[UIImage imageNamed:@"dainzan"] forState:UIControlStateNormal];
            }else{
                [self.midouView.zanButton setImage:[UIImage imageNamed:@"点赞-1"] forState:UIControlStateNormal];
            }
            //判断是否报名
            if ([self.dicData[@"isSignUp"] isEqualToString:@"是"]) {
                self.btnBaoMing.userInteractionEnabled = NO;
                [self.btnBaoMing setTitle:@"已报名" forState:UIControlStateNormal];
            }else {
                self.btnBaoMing.userInteractionEnabled = YES;
                [self.btnBaoMing setTitle:@"我要报名" forState:UIControlStateNormal];
            }
            
            //顶部图片
            [self.TopPhotos addObject:self.dicData[@"logo"]];
            for (NSString *str in self.dicData[@"photos"]) {
                [self.TopPhotos addObject:str];
            }
            
            //报名
            self.activitySignPeople = self.dicData[@"activitySignPeople"];
            //评论
            self.commentsList = [NSMutableArray arrayWithArray:self.dicData[@"commentsList"]];
            
            if (self.commentsList.count == 10) {
                self.scrollView.mj_footer.hidden = NO;
            }else {
                self.scrollView.mj_footer.hidden = YES;
            }
            
            [self.tableView reloadData];
            [self setupTopView];
            [self hideBubble];
        }else {

            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];

        }
        
        [self.scrollView.mj_footer endRefreshing];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self.scrollView.mj_footer endRefreshing];

        [self showSingleIconBubble:error.localizedDescription];

    }];
   
}







@end
